package com.pesking.core.sqlparser.processor;

import java.util.Arrays;
import java.util.List;

import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;
import com.pesking.core.util.LogUtils;
import com.pesking.core.util.StringUtils;

public class OrderBySqlParameterHandler extends SqlParameterProcessor {

	@Override
	public void handle(StringBuilder sbSQL, Parameter parameter, List<SqlParameter> processors,SqlParameter sqlParameter) {
		String name = sqlParameter.getName();
		if (StringUtils.isBlank(name)){
			name = "order_by_sql_equal";
		}
		String value = parameter.getParameter(name);
		if (!StringUtils.isBlank(value)){
			sbSQL.append(" order by ").append(value);
		}
		else{
			LogUtils.debug("ORDER_BY参数从请求中并未取得对应值。");
		}
	}

	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"ORDER_BY"});
	}

}
